package com.studio701.carguard.controller;


import com.studio701.carguard.pojo.CarManagement;
import com.studio701.carguard.pojo.HelpAnswer;
import com.studio701.carguard.pojo.RespBean;
import com.studio701.carguard.service.ICarManagementService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xjc
 * @since 2022-03-29
 */
@RestController
@RequestMapping("/car-management")
public class CarManagementController {

    @Autowired
    ICarManagementService iCarManagementService;

    @ApiOperation("添加车辆")
    @PostMapping("/")
    public boolean insertCar(@RequestBody CarManagement carManagement){
        return iCarManagementService.save(carManagement);
    }

    @ApiOperation("修改车俩信息")
    @PutMapping("/")
    RespBean updateCar(@RequestBody CarManagement carManagement){
        if (iCarManagementService.updateByUserIdAndCId(carManagement)){
            return RespBean.success("更新成功");
        }else {
            return RespBean.error("更新失败");
        }
    }

    @ApiOperation("删除车辆")
    @DeleteMapping("/")
    RespBean deleteCar(Integer userId, Integer cId){
        if (iCarManagementService.removeCarByUserIdAndCId(userId, cId)){
            return RespBean.success("删除成功");
        }else {
            return RespBean.error("删除失败");
        }
    }

    @ApiOperation("获取车俩")
    @GetMapping("/")
    CarManagement getCarByUserIdAndCId(Integer userId, Integer cId){
        return iCarManagementService.getCarByUserIdAndCId(userId, cId);
    }
}
